home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / UIs / UI Holder / ui.cpp < prev    next >
C/C++ Source or Header  |  2002-09-03  |  3KB  |  98 lines

  1. // ui.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include <Windows.h>
  5. #include <CommCtrl.h>
  6. #include "resource.h"
  7.  
  8. HINSTANCE g_hInstance;
  9. HWND m_curwnd;
  10.  
  11. char* windows[] = {
  12.   MAKEINTRESOURCE(IDD_LICENSE),
  13.   MAKEINTRESOURCE(IDD_SELCOM),
  14.   MAKEINTRESOURCE(IDD_DIR),
  15.   MAKEINTRESOURCE(IDD_INSTFILES),
  16.   MAKEINTRESOURCE(IDD_UNINST)
  17. };
  18.  
  19. BOOL CALLBACK GenericProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
  20.   static LOGBRUSH b = {BS_SOLID, RGB(255,0,0), 0};
  21.   static HBRUSH red = CreateBrushIndirect(&b);
  22.   switch (uMsg) {
  23.     case WM_CTLCOLORSTATIC:
  24.       return (int)red;
  25.   }
  26.   return 0;
  27. }
  28.  
  29. BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) {
  30.   static int i = -1;
  31.     switch (uMsg) {
  32.     case WM_INITDIALOG:
  33.         SetWindowText(hwndDlg, "NSIS User Interface - Testing");
  34.         SetWindowText(GetDlgItem(hwndDlg, IDC_VERSTR), "NSIS version");
  35.         SetWindowText(GetDlgItem(hwndDlg, IDC_BACK), "< Back");
  36.         SetWindowText(GetDlgItem(hwndDlg, IDOK), "Next >");
  37.         SetWindowText(GetDlgItem(hwndDlg, IDCANCEL), "Cancel");
  38.         ShowWindow(GetDlgItem(hwndDlg, IDC_BACK), SW_SHOW);
  39.         ShowWindow(GetDlgItem(hwndDlg, IDC_CHILDRECT), SW_SHOW);
  40.     SendMessage(hwndDlg, WM_COMMAND, MAKEWORD(IDOK, 0), 0);
  41.         ShowWindow(hwndDlg, SW_SHOW);
  42.         break;
  43.     case WM_COMMAND:
  44.     switch (LOWORD(wParam)) {
  45.     case IDOK:
  46.     case IDC_BACK:
  47.       i+=(LOWORD(wParam)==IDOK)?1:-1;
  48.       if (i < 0) {
  49.         i++;
  50.         break;
  51.       }
  52.       if (i >= (int)sizeof(windows)/sizeof(char*)) {
  53.         i--;
  54.         break;
  55.       }
  56.       if (m_curwnd) DestroyWindow(m_curwnd);
  57.       m_curwnd=CreateDialog(g_hInstance,windows[i],hwndDlg,GenericProc);
  58.       if (m_curwnd)
  59.       {
  60.         RECT r;
  61.         GetWindowRect(GetDlgItem(hwndDlg,IDC_CHILDRECT),&r);
  62.         ScreenToClient(hwndDlg,(LPPOINT)&r);
  63.         SetWindowPos(m_curwnd,0,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
  64.         ShowWindow(m_curwnd,SW_SHOWNA);
  65.       }
  66.       break;
  67.     default:
  68.       EndDialog(hwndDlg, 0);
  69.       PostQuitMessage(0);
  70.       break;
  71.     }
  72.     break;
  73.     }
  74.     return 0;
  75. }
  76.  
  77. int APIENTRY WinMain(HINSTANCE hInstance,
  78.                      HINSTANCE hPrevInstance,
  79.                      LPSTR     lpCmdLine,
  80.                      int       nCmdShow)
  81. {
  82.   InitCommonControls();
  83.  
  84.   LoadLibrary("RichEd32.dll");
  85.  
  86.   g_hInstance = GetModuleHandle(0);
  87.  
  88.     DialogBox(
  89.         GetModuleHandle(0),
  90.         MAKEINTRESOURCE(IDD_INST),
  91.         0,
  92.         DialogProc
  93.     );
  94.  
  95.     ExitProcess(0);
  96.  
  97.     return 0;
  98. }